<?php defined('SYSPATH') or die('No direct script access.');
$ss         = Session::instance();
$mydatetime = Helper_MyDateTime::factory();
$arraylist  = Helper_ArrayList::factory();
$display    = Helper_DisplayItems::factory();

$r          = Request::current();
$action     = $r->uri2();

$kriteria   = $ss->get('kriteria');
?>

<SCRIPT language="JavaScript">
<!--
function validEmail(mail) {
			invalidChars = " /:"
			if (mail == "") {
				return (false);
			}
			for (i=0; i < invalidChars.length; i++) {
				badChar = invalidChars.charAt(i)
				if (mail.indexOf(badChar,0) != -1) {
					return (false);
				}
			}
			atPos = mail.indexOf("@", 1)
			if (atPos == -1) {
				return (false);
			}
			periodPos = mail.indexOf(".", atPos)
			if (periodPos == -1) {
				return (false);
			}
			if (periodPos + 3 > mail.length) {
				return (false);
			}
			return (true);
		}
		
function checkPost() {
			if (document.updatePost.nama.value=="")
			{
				alert("Masukan nama !");
				document.updatePost.nama.focus();
				return false;
			}
			
			if (document.updatePost.address.value=="")
			{
				alert("Masukan alamat Lengkap !");
				document.updatePost.address.focus();
				return false;
			}

			if (document.updatePost.phone.value=="")
			{
				alert("Masukan No Telepon !");
				document.updatePost.phone.focus();
				return false;
			}
			if (document.updatePost.email.value=="")
			{
				alert("Masukan Email !");
				document.updatePost.email.focus();
				return false;
			}


			if (document.updatePost.hpassword.value=="")
			{
				alert("Masukan Password !");
				document.updatePost.hpassword.focus();
				return false;
			}
			
		}

function newPassword() {
			if (document.newPass.new_password.value=="")
			{
				alert("Password Tidak Boleh Kosong !!");
				document.newPass.new_password.focus();
				return false;
			}
			if (document.newPass.retype_password.value=="")
			{
				alert("Tulis Lagi Password Anda !");
				document.newPass.retype_password.focus();
				return false;
			}
			if (!(document.newPass.new_password.value==document.newPass.retype_password.value))
			{
				alert("Password Harus Sama !");
				document.newPass.retype_password.focus();
				return false;
			}
		}

//-->
</SCRIPT>
<style type="text/css">
.modalDialog > div {
width: <?php echo (!empty($userupdate['id']) ? '80%' : '50%')  ?>;
margin: 2% auto;
}
</style>
<?php 
	echo View::factory('module/apps_breadcrumb')
		->set('breadcrumbs',
			array(
				0=>array(
					'address'=>'index',
					'text'=>'Dashboard'
				),
				1=>array(
					'address'=>NULL,
					'text'=>"Karyawan"
				)
			)
		)
		->render();
?>

<?php echo View::factory('module/apps_message')->render(); ?>


<div class="row-fluid">
	<div class="span12">
		<div class="span5">
			<div class="row-fluid"> 
			<div class="span12">
			<?php echo Form::open($action.URL::query(array()), array('enctype'=>'multipart/form-data','name'=>'updatePost2', 'onSubmit'=>'return checkPost()'))?>
			<?php echo Form::hidden('command','')?>
			<div>
		   		<?php
					echo Form::select('key', array('0'=>'pilih','id'=>'id','address'=>'alamat','email'=>'email','nama'=>'nama'),'',
					array
					(
						'id'=>'key',
						'class'=>'span3',
						'placeholder'=>''
					)
				);
				?>
		   		<?php
					echo Form::input('value',"",
					array
					(
						'id'=>'value',
						'class'=>'span5',
						'placeholder'=>''
					)
				);
				?>
			<?php echo Form::submit('submit','submit',array('class'=>'btn btn-inverse')) ?>
			</div>

			<?php echo form::close(); ?>

		</div>
		</div>
			<!-- User Table Starts -->
			<div class="row-fluid">
				<div class="">		
					<div class="span12">
					<div style="border-top: 1px solid black;">
					<?php echo Form::open($action.URL::query(array()), array('enctype'=>'multipart/form-data','name'=>'', 'method'=>'GET'))?>
					<?php echo Form::hidden('command','')?>
				   		Page <?php
							echo Form::select('page', array('1'=>'1','2'=>'2','3'=>'3','4'=>'4','5'=>'5','6'=>'6','7'=>'7','8'=>'8','9'=>'9','10'=>'10'),'',
							array
							(
								'id'=>'page',
								'class'=>'span2',
								'style'=>'margin-top: 5px;'
							)
						);
						?>
				   		Item Per Page <?php
							echo Form::select('rpp',array('5'=>'5','10'=>'10','15'=>'15','20'=>'20','25'=>'25','30'=>'30','35'=>'35','40'=>'40'),'',
							array
							(
								'id'=>'rpp',
								'class'=>'span2',
								'style'=>'margin-top: 5px;'
							)
						);
						?>
					<?php echo Form::submit('submit','submit',array('class'=>'btn btn-danger btn-small')) ?>

					<?php echo form::close(); ?>
					</div>

				</div>
				</div>
				</div>
				<div class="row-fluid">
				<div class="box" style="clear: right;">
					<div class="box-content">
						<table class="table table-bordered table-striped table-condensed table-hover">
						  <thead>
							  <tr>
								  <th width="50">ID</th>
								  <th width="">Nama</th>                                     
								  <th width="50">action</th>                                           
							  </tr>
						  </thead>   
						  <tbody>
							<?php if(empty($userlists)) { ?>
							  <tr valign="middle">
							    <td colspan="6" valign="middle" style="text-align: center;"><strong>Tidak ada data tersedia.</strong></td>
							  </tr>
							<?php } else { ?>
							  <?php foreach($userlists as $userlist) { ?>
								<tr>
									<td><?php echo $userlist['id'] ?></td>
									<td><?php echo $userlist['nama'] ?></td>
									<td style="text-align: center;">
							      <a href="<?php echo 'karyawan'.URL::query(array('id'=>$userlist['id'])) ?>#openModal"><?php echo HTML::image('assets/global/images/edit.png')?></a>&nbsp;
							      <a href="<?php echo 'karyawan'.URL::query(array('command'=>'delete','id'=>$userlist['id'])) ?>" onclick="return confirm('Are you sure?');"><?php echo HTML::image('assets/global/images/delete.png')?></a>
									</td>
								</tr>
							  <?php } ?>
							<?php } ?>
						  </tbody>
						</table>
						
						<div class="pagination pagination-centered">
							<?php echo $pagination; ?>
						</div>
						
					</div>
				</div>
			</div>
			<!-- User Table End -->
		</div>
		<div class="span7">
			<!-- Forms Starts -->
			<div class="row-fluid">
				<!-- Main Container Starts -->
				<div class="span12 outer-well">
				
					<div class="row-fluid">
						
						<!-- Left Container Starts -->
						<div class="<?php echo (!empty($userupdate['id']) ? 'span8' : 'span12')  ?>">
							
							<!-- User Data Starts -->
							<div class="row-fluid"> 
								<?php echo Form::open($action.URL::query(array('id'=>$userupdate['id'])), array('class'=>'form-horizontal','enctype'=>'multipart/form-data','name'=>'updatePost', 'onSubmit'=>'return checkPost()'))?>
								<fieldset class="well">
								<font style=""><a href="<?php echo 'karyawan'.URL::query(array('command'=>NULL,'id'=>NULL)) ?>#openModal" class="btn btn-warning ">Tambah Baru</a></font>
									<?php if(!empty($userupdate['id'])) { ?>
									<?php echo Form::hidden('command','update')?>
									<?php } else { ?>
									<?php echo Form::hidden('command','create')?>
									<?php } ?>
								  <legend>Form Karyawan</legend>
								  <div class="control-group">
										<label class="control-label" for="id">ID Karyawan</label>
										<div class="controls">
										<?php $idmax = $display->show_max_id2('200','users','id'); ?>
										<?php $a = substr($idmax, 1); ?>
										<?php $b = $a+1; ?>
								    	<b style="margin: 10px;font-size: 14px;"><?php echo (!empty($userupdate['id']) ? $userupdate['id'] : 'K'.$b) ?></b>
										<input type='hidden' name='id' value='<?php echo (!empty($userupdate['id']) ? $userupdate['id'] : 'K'.$b); ?>'>
										</div>
									</div>
									
								  <div class="control-group">
										<label class="control-label" for="nama">Nama</label>
										<div class="controls">
								    <?php
											echo Form::input('nama', $userupdate['nama'],
											array
											(
												'id'=>'nama',
												'class'=>'span7',
												'placeholder'=>'Nama'
											)
										);
										?>
										</div>
									</div>
								  
								  <div class="control-group">
										<label class="control-label" for="address">Alamat</label>
										<div class="controls">
								    <?php
											echo Form::textarea ('address', $userupdate['address'],
											array(
												'id'=>'address',
												'class'=>'autogrow',
												'rows'=>3,
												'placeholder'=>'Masukan Alamat anda'
											)
											);
										?>
										</div>
									</div>

								  <div class="control-group">
										<label class="control-label" for="phone">No Telepon</label>
										<div class="controls">
								    <?php
											echo Form::input('phone', $userupdate['phone'],
											array
											(
												'id'=>'phone',
												'class'=>'span5',
												'placeholder'=>'Masukan No Telepon'
											)
										);
										?>
										</div>
									</div>
								  <div class="control-group">
										<label class="control-label" for="email">Email</label>
										<div class="controls">
								    <?php
											echo Form::input('email', $userupdate['email'],
											array
											(
												'id'=>'email',
												'class'=>'span5',
												'placeholder'=>'Masukan Email'
											)
										);
										?>
										</div>
									</div>
								  
								  <?php if(empty($userupdate['id'])) { ?>
								  <div class="control-group">
										<label class="control-label" for="hpassword">Password</label>
										<div class="controls">
								    <?php
											echo Form::input('hpassword', '',
											array
											(
												'id'=>'hpassword',
												'class'=>'span4',
												'placeholder'=>'Masukan Password'
											)
										);
										?>
										</div>
									</div>
								  <?php } ?>
								  
								  <?php echo Form::submit('submit','save',array('class'=>'btn btn-inverse btn-primary pull-right')) ?>
								</fieldset>
								<?php echo Form::close()?>
							</div>
							<!-- User Data End -->
							
						</div>
						<!-- Left Container End -->
						
						<!-- Right Container Starts -->
						<div class="span4">
													
							<!-- Password Container Starts -->
							<div class="row-fluid">
								<?php if(!empty($userupdate['id'])) { ?>
								<?php echo Form::open($action.URL::query(array('id'=>$userupdate['id'])), array('class'=>'form-horizontal','name'=>'newPass', 'onSubmit'=>'return newPassword()'))?>
								<?php echo Form::hidden('command','password_update')?>
						    <fieldset class="well">
							    <legend>Ubah Password</legend>
							    
							    <div class="control-group">
								    <?php
											echo Form::input('new_password', '',
											array
											(
												'id'=>'new_password',
												'class'=>'span12',
												'placeholder'=>'Masukan Password Baru'
											)
										);
										?>
									</div>
							    
							    <div class="control-group">
								    <?php
											echo Form::input('retype_password', '',
											array
											(
												'id'=>'retype_password',
												'class'=>'span12',
												'placeholder'=>'Masukan Password Kembali'
											)
										);
										?>
									</div>
									
							    <?php echo Form::submit('submit','submit',array('class'=>'btn btn-danger btn-block')) ?>
								</fieldset>
								<?php echo Form::close()?>
								<?php } ?>
							</div>
							<!-- Password Container End -->
							
						</div>
						<!-- Right Container End -->
						
					</div>
								
				</div>
				<!-- Main Container End -->
			</div>
			<!-- Forms End -->
		</div>
	</div>
</div>








